from django.db import models
from datetime import datetime
from django.contrib import admin

class cClass(models.Model):
    subject = models.CharField(
             max_length = 5)
    coursen = models.CharField(
             max_length = 3)
    dept = models.CharField(
             max_length = 45)
    title = models.CharField(
             max_length = 100)
    desc = models.TextField()

    class Meta:
        unique_together = ("subject", "coursen")
        
    def __unicode__(self):
        return "%s %s" %(self.subject, self.coursen)

class Course(models.Model):
    supclass = models.ForeignKey(cClass) 
    crn = models.CharField(max_length = 5)
    credits = models.CharField(max_length = 1)
    days = models.CharField(max_length=7)
    Btime = models.CharField(max_length=11)
    Etime = models.CharField(max_length=11)
    instructor = models.ForeignKey("Instructor")
    location = models.CharField(max_length = 25)
    books = models.ManyToManyField("Books")

    def __unicode__(self):
        return "%s %s" %(self.crn, self.supclass)
class Instructor(models.Model):
    name = models.CharField(max_length = 25, primary_key = True)
    email = models.CharField(max_length = 25, null =True)
    url = models.URLField(verify_exists = False,
                          null = True)
    def save(self):
        self.email = self.name+"@western.edu" 
        super(Instructor, self).save()  
    def __unicode__(self):
        return self.name                   
                          
class Books(models.Model):
    isbdn = models.CharField(
            max_length = 13,
            unique = True,
            help_text = "The International Standard Book Number")
    used = models.FloatField(null = True, blank = True)
    new = models.FloatField(null = True, blank = True)
    
admin.site.register(Instructor)
admin.site.register(cClass)
admin.site.register(Course)

